
import React from "react";
import * as THREE from 'three';
import Controller from "../Controller";

/** 摄像头 */
export default function useCamera(controller: Controller) {

    /** canvas 容器 */
    const cont = controller.useMemo(s => s.cont, []);

    React.useEffect(() => {
        if (!cont) return;

        controller.run(async s => {

            // 创建摄像机
            s.camera = new THREE.PerspectiveCamera(75, cont.offsetWidth / cont.offsetHeight, 0.1, 1000);
            s.camera.position.set(0, 5, 5);            
        })
    }, [cont, controller])
}